package com.xdcplus.web.controller.alarm;

import com.xdcplus.exceptions.domain.ResponseVO;
import com.xdcplus.mom.controller.AbstractController;
import com.xdcplus.web.common.pojo.dto.alarm.ToolAlarmGroupToolDTO;
import com.xdcplus.web.common.pojo.dto.alarm.ToolAlarmGroupToolFilterDTO;
import com.xdcplus.web.common.pojo.vo.alarm.FindToolAlarmGroupToolVO;
import com.xdcplus.web.service.alarm.ToolAlarmGroupToolService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.Validation;


/**
 * 设备告警组与设备关联表(ToolAlarmGroupTool)表服务控制层
 *
 * @author bullion.yan
 * @since 2024-06-05 16:16:14
 */
@Api(tags = "设备告警组与设备关联表(ToolAlarmGroupTool)") 
@Slf4j
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("toolAlarmGroupTool")
public class ToolAlarmGroupToolController extends AbstractController {

    @Autowired
    private ToolAlarmGroupToolService toolAlarmGroupToolService;


    @ApiOperation("查询设备告警组与设备关联表")
    @GetMapping(value = "findToolAlarmGroupTool", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO<FindToolAlarmGroupToolVO> findToolAlarmGroupTool(@Valid ToolAlarmGroupToolFilterDTO toolAlarmGroupToolFilterDTO) {
        Validation.buildDefaultValidatorFactory().getValidator().validate(toolAlarmGroupToolFilterDTO);
        return ResponseVO.success(toolAlarmGroupToolService.findToolAlarmGroupTool(toolAlarmGroupToolFilterDTO.getGroupIdFk(),toolAlarmGroupToolFilterDTO.getRegionId()));
    }

    @ApiOperation("新增设备告警组与设备关联表")
    @PostMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO saveToolAlarmGroupTool(@Valid @RequestBody ToolAlarmGroupToolDTO toolAlarmGroupToolDTO) {
        toolAlarmGroupToolDTO.setCreatedUser(getAccount());
        toolAlarmGroupToolService.saveToolAlarmGroupTool(toolAlarmGroupToolDTO);
        return ResponseVO.success();
    }

}
